import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/m_room/constants/room_assets.dart';

class SharingPlatformModel {
  final String code;
  final String title;
  final String icon;

  const SharingPlatformModel(
    this.code, {
    required this.title,
    required this.icon,
  });
}

List<SharingPlatformModel> sharingPlatformModels = [
  const SharingPlatformModel("Facebook",
      title: "Facebook", icon: "assets/images/me/ic_launcher.png"),
  const SharingPlatformModel("Twitter",
      title: "Twitter", icon: "assets/images/me/ic_launcher.png"),
  const SharingPlatformModel("Instagram",
      title: "Instagram", icon: "assets/images/me/ic_launcher.png"),
  const SharingPlatformModel("WhatsApp",
      title: "WhatsApp", icon: "assets/images/me/ic_launcher.png"),
];

class RoomShare extends StatelessWidget {
  const RoomShare({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return IntrinsicHeight(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            height: 12.h,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Padding(
                padding: EdgeInsetsDirectional.only(start: 19.w,top: 3.h,bottom: 3.h),
                child: "Cancel".text(
                  fontSize: 16.sp,
                  color: const Color(0xFFC1C1C1),
                  weight: TextFontWeight.regular,
                ),
              ),
              "Share".text(
                fontSize: 22.sp,
                color: Colors.white,
                weight: TextFontWeight.medium,
              ),
              Padding(
                padding: EdgeInsetsDirectional.only(end: 19.w,top: 3.h,bottom: 3.h),
                child: "Cancel".text(
                  fontSize: 16.sp,
                  color: Colors.transparent,
                  weight: TextFontWeight.regular,
                ),
              ),
            ],
          ),
          SizedBox(
            height: 18.h,
          ),
          _buildSharingPlatform(context),
          SizedBox(
            height: 7.h,
          ),
          _buildSharingFriend(context),
        ],
      ),
    );
  }

  Widget _buildSharingPlatform(BuildContext context) {
    return Padding(
      padding: EdgeInsetsDirectional.symmetric(horizontal: 16.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly, // 均等分
        children: sharingPlatformModels.map((model) {
          return Column(
            children: [
              Image.asset(
                model.icon,
                width: 56.w,
                height: 56.h,
              ),
              SizedBox(
                height: 7.h,
              ),
              model.title.text(
                fontSize: 12.sp,
                color: Colors.white,
                weight: TextFontWeight.medium,
              ),
            ],
          );
        }).toList(),
      ),
    );
  }

  Widget _buildSharingFriend(BuildContext context) {
    return  SizedBox(
      height: 300.h,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
         Padding(
           padding: EdgeInsetsDirectional.only(start: 16.w),
           child: "Invite Friends".text(
              fontSize: 18.sp,
              color: Colors.white,
              weight: TextFontWeight.medium,
           ),
         ),
          SizedBox(
            height: 11.h,
          ),
          Expanded(
            child: ListView.separated(
              itemCount: 3,
              separatorBuilder: (context, index) {
                return Divider(
                  color: const Color(0xFF3E2654),
                  height: 0.5.h,
                  thickness: 0.5.h,
                  indent: 0,
                  // 左侧缩进
                  endIndent: 0, // 右侧缩进
                );
              },
              itemBuilder: (context, index) {
                return _friendItem();
              },
            ),
          ),
        ],
        ),
    );
  }

  Widget _friendItem() {
    return Container(
      height: 55.h,
      alignment: AlignmentDirectional.centerStart,
      padding: EdgeInsetsDirectional.only(start: 15.w, end: 20.w),
      child: Row(
        children: [
          CircleAvatar(
            backgroundColor: Color(0xFFFFFFFF),
            radius: 20.r,
            backgroundImage: const CachedNetworkImageProvider(
                'https://picsum.photos/200/300'),
          ),
          SizedBox(width: 8.w),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                  "Usre Name".text(
                    fontSize: 16.sp,
                    color: Colors.white,
                  ),
                  Container(
                    height: 14.h,
                    padding: EdgeInsets.symmetric(horizontal: 4.w),
                    decoration: BoxDecoration(
                      color: Color(0xFFFF7D99),
                      borderRadius: BorderRadius.circular(4.r),
                    ),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Image.asset(RoomAssets.roomFriendNv, width: 10.w, height: 10.h),
                        SizedBox(width: 1.w),
                        "18".text(
                          fontSize: 11.sp,
                          color: Colors.white,
                          weight: TextFontWeight.medium,
                        ),
                      ],
                    ),
                  )
              ],
            ),
          ),
          Container(
            height: 28,
            alignment: AlignmentDirectional.center,
            padding: EdgeInsets.symmetric(horizontal: 11.w),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(8.r),
              gradient: const LinearGradient(
                colors: [
                  Color(0xFF8A72FE),
                  Color(0xFF6549EC),
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
            child: "Invite".text(
              fontSize: 14.sp,
              color: Colors.white,
              weight: TextFontWeight.medium,
            ),
          ),
        ]
      )
    );
  }


}
